import { defineStore } from "pinia";
import { ref } from "vue";
import { fetchCategoryAPI } from "@/api/categoryApi";
import type { Category } from "@/types/cate";

export const useCategoryStore = defineStore("categoryStore", () => {

    const category = ref<Category>(<Category>{});

    const fetchCategory = async (id: string): Promise<void> => {
        const { result }: { result: Category } = await fetchCategoryAPI(id);
        category.value = result;
    };

    return {
        category,
        fetchCategory,
    };
});

export default useCategoryStore;
